package com.lanqiao.gxnushop.controller;

import com.lanqiao.gxnushop.entity.Promotions;
import com.lanqiao.gxnushop.service.PromotionsService;
import com.lanqiao.gxnushop.util.UUIdUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Log4j
@Tag(name = "PromotionsController",description="促销管理")
@RestController
public class PromotionsController {
    @Autowired
    private PromotionsService promotionsService;

    @PostMapping("/promotions")
    @Operation(summary="增加促销信息")
    @Parameter(name = "promotions",description = "促销信息promotionId(自动生成),storeId(店铺Id),name(促销活动名称),discountType(折扣类型),discountValue(折扣值),startDate(开始时间),endDate(结束时间),state(促销状态（如1 \"进行中\"、0\"已结束\".2未开始）)")
    public boolean addPromotions(Promotions promotions)
    {
        return promotionsService.addPromotions(promotions);
    }

    @DeleteMapping("/promotions/{promotionId}")
    @Operation(summary="根据促销活动Id删除指定的促销信息")
    @Parameter(name = "promotionId",description = "促销promotionId")
    public boolean deletePromotions(@PathVariable String promotionId)
    {
        return promotionsService.delete(promotionId);
    }

    @PutMapping("/promotions")
    @Operation(summary="根据promotionId更新指定促销信息")
    @Parameter(name = "promotions",description = "促销信息promotionId")
    public boolean updatePromotions(Promotions promotions)
    {
        return promotionsService.update(promotions);
    }

    @GetMapping("/promotions/{promotionId}")
    @Operation(summary="根据促销id查询促销信息")
    @Parameter(name = "promotionId",description = "促销promotionId")
    public Promotions findById(@PathVariable String promotionId)
    {
        return promotionsService.select(promotionId);
    }

    @GetMapping("/promotions")
    @Operation(summary="查询所有促销信息")
    public ArrayList<Promotions> findAll()
    {
        return promotionsService.selectAll();
    }
}
